package cn.group.controller;

import cn.group.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import pojo.entity.Account;

import java.util.List;

@Api(tags = "账户信息")
@Controller
@RequestMapping(value = "/account" , produces = "text/html;charset=UTF-8")
public class AccountController {

    @Autowired
    private AccountService accountService;

    //保存
    @ApiOperation("添加账户")
    @RequestMapping("/save")
    @ResponseBody
    public String save(Account account){
        accountService.save(account);
        return "订单保存成功";
    }

    //查询
    @ApiOperation("查询所有账户")
    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        List<Account> accountList = accountService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accountList",accountList);
        modelAndView.setViewName("/accountList.jsp");
        return modelAndView;
    }

    //修改
    @ApiOperation("修改指定账户")
    @RequestMapping("/update")
    public void update(Account account){
        accountService.update(account);
    }

    //删除
    @ApiOperation("修改指定账户")
    @RequestMapping("/delete")
    public void delete(int id){
        accountService.delete(id);
    }
}
